package xdb;

import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

public interface ExecutorMBean {
    long getExecutorTaskCount();

    long getExecutorCompletedTaskCount();

    int getExecutorActiveCount();

    int getExecutorPoolSize();

    String getExecutorState();

    long getProcedureTaskCount();

    long getProcedureCompletedTaskCount();

    int getProcedureActiveCount();

    int getProcedurePoolSize();

    String getProcedureState();

    long getScheduledTaskCount();

    long getScheduledCompletedTaskCount();

    int getScheduledActiveCount();

    int getScheduledPoolSize();

    String getScheduledState();

    /**
     * Tries to remove from the work queue all Future tasks that have been cancelled.
     * see java.util.concurrent.ThreadPoolExecutor.purge
     *
     * @param iamsure 必须输入"iamsure"，防止误操作。
     */
    void purgeExecutor(String iamsure);

    /**
     * Tries to remove from the work queue all Future tasks that have been cancelled.
     * see java.util.concurrent.ThreadPoolExecutor.purge
     *
     * @param iamsure 必须输入"iamsure"，防止误操作。
     */
    void purgeScheduled(String iamsure);

    void purgeProcedure(String iamsure);

    int getExecutorCorePoolSize();

    void setExecutorCorePoolSize(int corePoolSize);

    int getProcedureCorePoolSize();

    void setProcedureCorePoolSize(int corePoolSize);

    int getScheduledCorePoolSize();

    void setScheduledCorePoolSize(int corePoolSize);

    long getExecutorDefaultTimeout();

    void setExecutorDefaultTimeout(long timeout);

    long getScheduledDefaultTimeout();

    void setScheduledDefaultTimeout(long timeout);

    long getProcedureDefaultTimeout();

    void setProcedureDefaultTimeout(long timeout);

    /**
     * Executor 是否活着。正常返回表示或者。异常表示已经死亡或者执行错误。
     *
     * @param timeout 设置检测超时时间，单位毫秒。小于500毫秒，将按500毫秒进行检查。实际检查时间可能超过这个值。
     * @throws CancellationException if the computation was cancelled
     * @throws ExecutionException    if the computation threw an exception
     * @throws InterruptedException  if the current thread was interrupted while waiting
     * @throws TimeoutException      if the wait timed out
     */
    void testAlive(long timeout)
            throws InterruptedException, ExecutionException, TimeoutException;
}
